package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.DaoSchoolTopSaveAdminDTO;
import com.sc.nft.entity.dto.DaoSchoolTopUpdateByIdAdminDTO;
import com.sc.nft.entity.vo.DaoSchoolTopPageAdminVO;
import com.sc.nft.service.DaoSchoolTopService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * dao学堂的一级分类(DaoSchoolTop)表控制层
 *
 * @author makejava
 * @since 2023-03-13 16:13:47
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/daoSchoolTop")
@Api(tags = "dao学堂的一级分类")
public class DaoSchoolTopController {

    /**
     * 服务对象
     */
    private final DaoSchoolTopService daoSchoolTopService;

    @ApiOperation(value = "列表", notes = "列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/pageAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<DaoSchoolTopPageAdminVO> pageAdmin(@RequestBody PageRequest pageRequest) {
        Page<DaoSchoolTopPageAdminVO> daoSchoolTopPageAdminVOPage = daoSchoolTopService.pageAdmin(pageRequest);
        return PageResult.success(daoSchoolTopPageAdminVOPage);
    }

    @ApiOperation(value = "新增", notes = "新增", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result saveAdmin(@Validated @RequestBody DaoSchoolTopSaveAdminDTO daoSchoolTopSaveAdminDTO) {
        return PageResult.success(daoSchoolTopService.saveAdmin(daoSchoolTopSaveAdminDTO));
    }

    @ApiOperation(value = "根据id修改", notes = "根据id修改", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateByIdAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateByIdAdmin(@Validated @RequestBody DaoSchoolTopUpdateByIdAdminDTO daoSchoolTopUpdateByIdAdminDTO) {
        return PageResult.success(daoSchoolTopService.updateByIdAdmin(daoSchoolTopUpdateByIdAdminDTO));
    }

    @ApiOperation(value = "根据id删除这个分组", notes = "根据id删除这个分组", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteByIdAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteByIdAdmin(@Validated @RequestBody IdRequest idRequest) {
        return PageResult.success(daoSchoolTopService.deleteById(idRequest.getId()));
    }

    @ApiOperation(value = "获取全部数据", notes = "获取全部数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/allAdmin", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<DaoSchoolTopPageAdminVO>> allAdmin() {
        return PageResult.success(daoSchoolTopService.allAdmin());
    }

}
